const { ipcRenderer, contextBridge } = require('electron');

const sendUrl = async (url) => {
  let res = await ipcRenderer.invoke('on-url-event', url)
  return res
};
const alert = (msg) => {
  ipcRenderer.invoke('on-alert-event', msg)
}

/**
 * @description: 打开窗口
 * @param {String} url
 * @return {*}
 */
const open = (url) => {
  ipcRenderer.invoke('on-open-event', url)
}
/**
 * @description: 获取图片列表
 */
const getFileList = async () => {
  let res = await ipcRenderer.invoke('on-getFiles-event')
  return res
}
/**
 * @description:打开添加窗口
 * @return {*}
 */
const openDialog = async () => {
  ipcRenderer.send('on-openDialog-event')
}
/**
 * @description:获取调用参数
 * @return {*}
 */
const onRendererEvent = (cbClick) => {
  ipcRenderer.on('on-renderer-event', (e, msg) => {
    cbClick(msg)
  })
}


contextBridge.exposeInMainWorld("myApi", {
  sendUrl,
  alert,
  open,
  getFileList,
  openDialog,
  onRendererEvent
})